import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Personaje here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public abstract class Personaje extends Actor
{
    protected int resistance;
    private boolean death;
    private Mensaje mensaje;

    /**
     * Act - do whatever the Personaje wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Personaje(int rest)
    {
        resistance=rest;
        death=false;
     //  mensaje=new Mensaje(""+resistance);
    }

  /*  public void addedToWorld(World world)
    {
        getWorld().addObject(mensaje,getX(),getY());
    }*/
   /* {
        getWorld().addObject(mensaje,getX(),getY());
    }*/
    
    public void decreaseResistance()
    {
        if(resistance>0)
        {
            resistance--;
        //    mensaje=new Mensaje(""+resistance);
          //  getWorld().addObject(mensaje,getX(),getY());
        }
    }

    public boolean isDead()
    {
        if(resistance==0)
            death=true;
        else
            death=false;
        return death;
    }

    public void detectWall1()
    {
        Wall1 wall=(Wall1)getOneIntersectingObject(Wall1.class);
        Grass grass=(Grass)getOneIntersectingObject(Grass.class);
        if(wall!=null)
        {  if(getX()<300 || getX()>400 && getX()<650)  
            {

                setLocation(getX()+5,getY());
                turn(10);
            }

            if(getX()>300 && getX()<400 || getX()>650)
            {
                setLocation(getX()-5,getY());
                turn(10);
            }
        }

    }
    
    public void detectOutWalls()
    {
        Wall1 wall=(Wall1)getOneIntersectingObject(Wall1.class);
        Wall2 wall2=(Wall2)getOneIntersectingObject(Wall2.class);
        Wall3 wall3=(Wall3)getOneIntersectingObject(Wall3.class);
        Wall4 wall4=(Wall4)getOneIntersectingObject(Wall4.class);
        if(wall!=null || wall2!=null)
       
            this.move(-10);
            if(wall3!=null || wall4!=null)
       
            this.move(-10);
          
        
      
     
        
    }

    public void detectWalls()
    {
        detectWall1();
        detectWall2();
    }

    public void detectWall2()
    {
        Wall2 wall=(Wall2)getOneIntersectingObject(Wall2.class);
        if(wall!=null)
        {
            if(getY()<getWorld().getHeight()/2)
            {
                setLocation(getX(),getY()+5);
                turn(-10);
            }
            if(getY()>getWorld().getHeight()/2)
            {
                setLocation(getX(),getY()-5);
                turn(-10);
            }

        }
    }
 
}
